<?php
/**
 * 产品显示
 * 
 * ============================================================================
 * 版权所有: (c) 2009-2011，<UEShop Inc>，并保留所有权利。
 * 网站地址: http://www.ueshop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 *
 * @author      cmpan
 * @copyright   Copyright (c) 2009-2010 UEShop Inc. (http://www.ueshop.cn)
 * @license     http://www.ueshop.cn/1_0.txt
 */
class ShowController extends UE_Controller_Action {	
	public function listAction() {
	    
	}
	
	public function itemAction() {
	    
	}
	
	public function getBrandsByCatIdAction() {		
		$cats = CatModel::getCats('product');
		$this->id = (int) $this->id;
		if (!$this->id || empty($cats[$this->id])) {
			print 'Error Param!';
			return ;
		}
		
		$cat = $cats[$this->id];
		
		$db = UE_DB::factory();
		$sql = "SELECT * FROM ue_brand b 
		        LEFT JOIN ue_brand_r_cat br ON b.brand_id = br.brand_id
		        WHERE br.cat_id IN ({$cat['chileId']})
		          AND b.brand_enabled=1
		          AND b.brand_is_trash=0
		        ORDER BY b.brand_order ASC, b.brand_id ASC";
		$rs = $db->getAll($sql);
		//print_r($rs);
		
		$brands = array();
		if ($rs) {
			foreach ($rs as $r) {
				$brands[$r['brand_id']] = array(
				    'brand_id' => $r['brand_id'],
				    'brand_name' => $r['brand_name'],
				    'cat_id' => $r['cat_id'],
				);
			}
		}
		//print_r($brands);
		header('Content-Type: text/javascript');
		print json_encode($brands);
	}
}